package com.imooc.maokeyang.alllearning.domain.common;

import com.imooc.maokeyang.alllearning.exception.ErrorCodeEnum;
import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseResult<T> implements Serializable {
    private static final long serialVersionUID = 912321312312321L;


    /**
     * 是否成功
     */
    private Boolean success;


    private String code;


    private String message;


    private T result;


    public static <T> ResponseResult<T> success(T result) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setSuccess(Boolean.TRUE);
        responseResult.setCode(ErrorCodeEnum.SUCCESS.getCode());
        responseResult.setResult(result);
        return responseResult;
    }


    public static <T> ResponseResult<T> failure(String code, String message) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setSuccess(Boolean.FALSE);
        responseResult.setCode(code);
        responseResult.setMessage(message);
        return responseResult;
    }

    public static <T> ResponseResult<T> failure(ErrorCodeEnum codeEnum) {
        return failure(codeEnum.getCode(), codeEnum.getMessage());
    }
}
